﻿Imports DTO
Imports System.Data.SqlClient

Public Class ThongTinDao

    Shared Function layThongTin() As ThongTinDTO
        Dim tt As New ThongTinDTO
        Dim cn As SqlConnection = CKetNoi.Connect
        Dim cmd As New SqlCommand
        cmd.CommandText = "usp_LayThongTin"
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Connection = cn
        cn.Open()
        Dim reader As SqlDataReader = cmd.ExecuteReader
        While reader.Read
            tt.Ma = reader("Ma")
            tt.TenDonVi = reader("TenDonVi").ToString
            tt.DiaChi = reader("DiaChi").ToString
            tt.Fax = reader("Fax").ToString
            tt.DienThoai = reader("DienThoai").ToString
            tt.TrangWEB = reader("Website").ToString
            tt.Email = reader("Email").ToString
            tt.MaLinhVuc = reader("MaLinhVuc").ToString
            tt.MaSoThue = reader("MaSoThue").ToString
            tt.GPKD = reader("GPKD").ToString
            tt.AnhDaiDien = DirectCast(reader("AnhDaiDien"), Byte())
        End While
        cn.Close()
        Return tt
    End Function

    Shared Function capNhatTT(tt As ThongTinDTO) As Integer
        Dim listVal As New List(Of SqlParameter)
        Dim para As SqlParameter

        para = New SqlParameter("AnhDaiDien", SqlDbType.Image)
        para.Direction = ParameterDirection.Input
        para.Value = tt.AnhDaiDien
        listVal.Add(para)


        para = New SqlParameter("TenDonVi", SqlDbType.NText)
        para.Direction = ParameterDirection.Input
        para.Value = tt.TenDonVi
        listVal.Add(para)

        para = New SqlParameter("DiaChi", SqlDbType.NText)
        para.Direction = ParameterDirection.Input
        para.Value = tt.DiaChi
        listVal.Add(para)

        para = New SqlParameter("Fax", SqlDbType.NText)
        para.Direction = ParameterDirection.Input
        para.Value = tt.Fax
        listVal.Add(para)

        para = New SqlParameter("DienThoai", SqlDbType.NText)
        para.Direction = ParameterDirection.Input
        para.Value = tt.DienThoai
        listVal.Add(para)

        para = New SqlParameter("Website", SqlDbType.NText)
        para.Direction = ParameterDirection.Input
        para.Value = tt.TrangWEB
        listVal.Add(para)

        para = New SqlParameter("Email", SqlDbType.NText)
        para.Direction = ParameterDirection.Input
        para.Value = tt.Email
        listVal.Add(para)

        para = New SqlParameter("MaLinhVuc", SqlDbType.VarChar, 7)
        para.Direction = ParameterDirection.Input
        para.Value = tt.MaLinhVuc
        listVal.Add(para)

        para = New SqlParameter("MaSoThue", SqlDbType.NText)
        para.Direction = ParameterDirection.Input
        para.Value = tt.MaSoThue
        listVal.Add(para)

        para = New SqlParameter("GPKD", SqlDbType.NText)
        para.Direction = ParameterDirection.Input
        para.Value = tt.GPKD
        listVal.Add(para)



        Return CKetNoi.ExecQueryStoreProc("usp_CapNhatThongTin", listVal)
    End Function

End Class
